package club.banyuan;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;

public class LetterThread extends Thread {

  private Lock lock;
  private Condition condition;

  public LetterThread(Lock lock, Condition condition) {
    this.lock = lock;
    this.condition = condition;
  }

  @Override
  public void run() {

    char aChar = 'A';
    try {
      lock.lock();
        while (aChar <= 'Z') {
          condition.await();
          System.out.printf("%s ", aChar);
          Thread.sleep(500);
          aChar++;
          condition.signal();
        }
      lock.unlock();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

  }
}
